package model;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;

import main.Core;
import dao.ContentManager;
import data.Vector2;

/**
 * Classe que serve como componente visual de texto.
 * Esta classe ignora "size".
 * @author Ygor
 *
 */
public class TextSprite extends Sprite {
	private Font font;
	private String text;
	private int fontSize;
	
	
	public TextSprite(String text, int fontSize, Vector2 pos, Vector2 speed, GameObject owner, Core core) {
		this("basic", text, fontSize, pos, speed, owner, core);
	}
	public TextSprite(String fontResource, String text, Vector2 pos, Vector2 speed, GameObject owner, Core core) {
		this(fontResource, text, 20, pos, speed, owner, core);
	}
	public TextSprite(String text, Vector2 pos, Vector2 speed, GameObject owner, Core core) {
		this("basic", text, 20, pos, speed, owner, core);
	}
	
	// construtor real
	public TextSprite(String fontResource, String text, int fontSize, Vector2 pos, Vector2 speed, GameObject owner, Core core) {
		super(fontResource, pos, Vector2.zero(), speed, owner, core);
		this.setText(text);
		this.fontSize = fontSize;
	}
	
	@Override
	public void load()
	{
		font = ContentManager.loadFont(getResource());
	}
	
	@Override
	public void render(Graphics2D g)
	{
		Font aux = g.getFont();
		g.setFont(font);
		g.setColor(Color.BLACK);
		g.drawString(getText(), getPosition().x + getOffset().x, getPosition().y + getOffset().y);

		g.setFont(aux);
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public int getFontSize() {
		return fontSize;
	}

	public void setFontSize(int fontSize) {
		this.fontSize = fontSize;
		this.font = new Font(font.getName(), font.getStyle(), fontSize);
	}
	
}
